<template>
  <div>
    <el-container>
      <el-header>
        <div class="box">
          <nav style="display: flex; justify-content: space-between">
            <div>
              <router-link to="/login" style="display: flex"
                ><img src="https://flowbite.com/docs/images/logo.svg" /><span
                  style="color: black; font-size: 28px"
                  >{{ title }}</span
                ></router-link
              >
            </div>
            <div>
              <el-menu
                :default-active="handleSelect"
                class="el-menu-demo"
                active-text-color="#4ec7ff"
                mode="horizontal"
                router
              >
                <el-menu-item index="/home/index">首页</el-menu-item>
                <el-menu-item index="/home/classify">分类</el-menu-item>
                <el-menu-item index="/home/tag">标签</el-menu-item>
                <el-menu-item index="/home/archive">归档</el-menu-item>
              </el-menu>
            </div>
            <div style="display: flex">
              <el-input v-model="input" placeholder="输入框待开发"></el-input>
              <div v-if="state == 0" style="width: 40px; margin-left: 20px">
                <!-- <router-link to="/login"> -->
                  <div @click="login" v-if="$store.state.zzz == 0">登录</div>
                  <div class="index" v-if="$store.state.zzz == 1">
                    <img :src="userimg" alt="" />
                    <span>{{ username }}</span>
                    <i class="el-icon-arrow-down"> </i>
                    <div>
                      <p @click="cdlogin">进入后台</p>
                      <p @click="closelogin">退出登录</p>
                    </div>
                  </div>
                <!-- </router-link> -->
              </div>
              <div v-else>
                <a href=""
                  ><img
                    src=""
                    alt=""
                    style="width: 20px; height: 20px; border-radius: 50%"
                /></a>
              </div>
            </div>
          </nav>
        </div>
      </el-header>
      <el-container class="box">
        <el-container>
          <el-main>
            <router-view></router-view>
          </el-main>
          <el-footer></el-footer>
        </el-container>
        <el-aside width="300px">
          <div style="margin-bottom: 10px">
            <router-view name="SideView"></router-view>
          </div>
          <div style="margin-bottom: 30px">
            <router-view name="Classify"></router-view>
          </div>
          <div>
            <router-view name="Tag"></router-view>
          </div>
        </el-aside>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { detail } from "../../units/api";
export default {
  data() {
    return {
      // activeIndex: "/home/index",//用于设置选中时样式标签名 已用计算属性代替
      input: "", //待开发搜索框的同步值
      state: 0, //是否登录 到时候赋值登陆上变为 1 默认是 0 显示 ‘登录’ 两个字 为 1 时显示头像img点击可以跳转到后台登陆页面
      title: "",
      username: "",
      userimg: "",
    };
  },

  computed: {
    handleSelect() {
      //计算属性触发 来自动选择上方导航栏的使用样式
      return this.$route.fullPath;
    },
  },
  created() {
    this.getUser();
  },
  methods: {
    async getUser() {
      let res = await detail();
      this.title = structuredClone(res.data.data.author);
      //   console.log(this.data);
      let res2 = await this.$axios.post("/api/admin/detail");
      console.log(res2, "主页信息");
      this.$nextTick(() => {
        this.username = res2.data.data.username;
        this.userimg = res2.data.data.avatar;
      });
    },
    closelogin() {
      // this.$router.replace({
      //   name: "login",
      // });
      this.$store.state.zzz  = 0

      this.$store.state.langing = false;
      if (localStorage.getItem("token")) {
        localStorage.removeItem("token");
      }
    },
    login() {
      this.$router.push({
        name: "login",
      });
    },
    cdlogin() {
      this.$router.push({
        name: "htindex",
      });
    },
  },
};
</script>

<style scoped lang="scss">
a {
  text-decoration: none;
}
.header {
  position: sticky;
  top: 0;
}
.box {
  width: 1400px;
  margin: 0 auto;
}
.el-header,
.el-footer {
  background-color: #fff;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container .el-aside {
  line-height: 260px;
}
.index {
  display: flex;
  align-items: center;
  position: relative;
  img{
    width:30px;
    height: 30px;
  }
  > div {
    width: 100px;
    height: 90px;
    line-height: 20px;
    background-color: #ffffff;
    text-align: center;
    position: absolute;
    bottom: -90px;
    display: none;
    z-index: 10;
    
    p {
      cursor: pointer;
      &:hover {
        color: #2dd5ff;
      }
      
    }
  }
  &:hover > div {
    display: block;
  }
}
</style>
